<?php
require('config.php');

$query="SELECT * FROM Spell WHERE class_id=".$_GET["class"];

$res=mysql_query($query);
$spells=array();

//echo $query;


echo mysql_error();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>untitled</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<style type="text/css">
		td{padding: 2px; border: 1px solid #E5E5E5}
	</style>
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script>
		<?php echo 'var user_id='.$_GET['pid'].';';?>
		$(function(){
			$('button').click(function(){
				var spells='';
				$("input:checked").each(function(){
					var id=$(this).parent().next().html();
					spells=spells+','+id;
				});
				spells=spells.slice(1);
				var msg={"spells": spells, "pid": user_id};
				$.post("save_spell.php", msg);
			});
			
		});
	
	
	
	</script>
</head>

<body>
<table style="font-size:x-small; border-collapse:collapse;">
	<thead style="font-weight: bold; background-color:grey;">
		<td>Select</td>
		<td>ID</td>
		<td>Name</td>
		<td>Decription</td>
		<td>School</td>
		<td>Components</td>
		<td>Cast time</td>
		<td>Range</td>
		<td>Target</td>
		<td>Duration</td>
		<td>Save</td>
		<td>SR</td>
		<td>PHP page</td>
		<td>Level</td>
		<td>Class ID</td>
		
	</thead>
	<?php
	$i=0;
	while($spells=mysql_fetch_assoc($res)){
		if ($i%2)
			echo '<tr>';
		else
			echo '<tr style="background-color:#F0F0F0">';
		echo '<td><input type="checkbox"/></td>';
		foreach ($spells as $spell)
			echo "<td>$spell</td>";
		echo '</tr>';
		$i++;
	}
	?>
</table>
<button style="float:right">Save</button>
</body>
</html>
